import eslintPluginUnicorn from "eslint-plugin-unicorn";
import globals from "globals";
import eslint from "@eslint/js";
import reactPlugin from "eslint-plugin-react";
import reactHooks from "eslint-plugin-react-hooks";
import jsxA11y from "eslint-plugin-jsx-a11y";
import nodePlugin from "eslint-plugin-n";

export default [
  {
    files: ["**/*.mjs", "**/*.cjs"],
    languageOptions: {
      globals: globals.builtin,
      ecmaVersion: "latest",
      sourceType: "module",
    },
    plugins: {
      ...eslintPluginUnicorn.configs.recommended.plugins,
      ...nodePlugin.configs["flat/recommended-script"].plugins,
    },
    rules: {
      ...eslintPluginUnicorn.configs.recommended.rules,
      ...nodePlugin.configs["flat/recommended-script"].rules,
      "n/no-unpublished-import": 0,
    },
  },
  {
    files: ["**/*.js"],
    languageOptions: {
      globals: globals.browser,
      ecmaVersion: "latest",
      sourceType: "module",
    },
    plugins: {
      ...eslintPluginUnicorn.configs.recommended.plugins,
    },
    rules: {
      ...eslint.configs.recommended.rules,
      ...eslintPluginUnicorn.configs.recommended.rules,
    },
  },
  {
    files: ["**/*.jsx"],
    languageOptions: {
      globals: globals.browser,
      ecmaVersion: "latest",
      sourceType: "module",
      parserOptions: {
        ecmaFeatures: { impliedStrict: true, jsx: true },
      },
    },
    settings: {
      react: {
        pragma: "h",
        version: "16.0",
      },
      "jsx-a11y": {
        attributes: {
          for: ["htmlFor", "for"],
        },
      },
    },
    plugins: {
      ...eslintPluginUnicorn.configs.recommended.plugins,
      ...reactPlugin.configs.flat.recommended.plugins,
      ...reactHooks.configs.flat["recommended-latest"].plugins,
      ...jsxA11y.flatConfigs.recommended.plugins,
    },
    rules: {
      ...eslint.configs.recommended.rules,
      ...eslintPluginUnicorn.configs.recommended.rules,
      ...reactPlugin.configs.flat.recommended.rules,
      ...reactHooks.configs.flat["recommended-latest"].rules,
      ...jsxA11y.flatConfigs.recommended.rules,
      "unicorn/filename-case": "off",
      "unicorn/prevent-abbreviations": "off",
      "react/prop-types": "off",
      "react/no-unknown-property": ["error", { ignore: ["class", "for"] }],
      "react/react-in-jsx-scope": 0,
      "react/display-name": [
        1,
        {
          ignoreTranspilerName: false,
        },
      ],
      "react/jsx-no-bind": [
        1,
        {
          ignoreRefs: true,
          allowFunctions: true,
          allowArrowFunctions: true,
        },
      ],
      "react/jsx-tag-spacing": [
        2,
        {
          beforeSelfClosing: "always",
        },
      ],
      "react/jsx-key": [
        2,
        {
          checkFragmentShorthand: true,
        },
      ],
    },
  },
];
